home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / bcfamily / source / memory.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-12  |  1.8 KB  |  87 lines

  1. //
  2. //      *******************************************************************
  3. //        JdeBP C++ Library Routines          General Public Licence v1.00
  4. //            Copyright (c) 1991,1992     Jonathan de Boyne Pollard
  5. //      *******************************************************************
  6. //
  7. // Part of FamAPI.LIB
  8. //
  9.  
  10. #include "famapi.h"
  11. #include "dosdos.h"
  12.  
  13. //
  14. //    Allocate memory
  15. //
  16. USHORT _APICALL
  17. DosAllocSeg    ( unsigned short Size,
  18.               unsigned short far *PtrSelector,
  19.               unsigned short AllocFlags )
  20. {
  21.     if (Size & 0xF)
  22.         _BX = (Size >> 4) + 1 ;        // Round up to next paragraph
  23.     else
  24.         _BX = Size >> 4 ;
  25.     _AH = 0x48 ;
  26.     Dos3Call() ;
  27.     if (_FLAGS & 0x0001) return _AX;
  28.     *PtrSelector = _AX ;
  29.     return NO_ERROR ;
  30. }
  31.  
  32. //
  33. //    Free memory
  34. //
  35. USHORT _APICALL
  36. DosFreeSeg    ( unsigned short Selector )
  37. {
  38.     _ES = Selector ;
  39.     _AH = 0x49 ;
  40.     Dos3Call() ;
  41.     return (_FLAGS & 0x0001) ? _AX : NO_ERROR;
  42. }
  43.  
  44. //
  45. //    Obtain available memory
  46. //
  47. USHORT _APICALL
  48. DosMemAvail    ( unsigned long far *PtrBlockSize )
  49. {
  50.     _BX = -1U ;                // Attempt to allocate 1Mb of memory
  51.     _AH = 0x48 ;
  52.     Dos3Call() ;            // Ignore error : This should always fail
  53.     asm {
  54.         xor dx,dx;
  55.         mov ax,bx;            // Take copy of BX
  56.         mov cx,4 ;
  57.         shl ax,cl;            // And left shift it for low word
  58.         push ax ;
  59.         mov ax,bx;            // Take copy of BX
  60.         mov cx,-4;
  61.         shl ax,cl;            // And right shift it for high word
  62.         mov dx,ax;
  63.         pop ax;
  64.         les bx,PtrBlockSize;
  65.         mov [es:bx], ax ;
  66.         mov [es:bx + 2], dx ;
  67.     }
  68. //    *PtrBlockSize = ((ULONG)_DX << 16) + _AX ;
  69.     return NO_ERROR;
  70. }
  71.  
  72. //
  73. //    Modify memory allocation
  74. //
  75. USHORT _APICALL
  76. DosReallocSeg ( unsigned short NewSize, unsigned short Selector )
  77. {
  78.     if (NewSize & 0xF)
  79.         _BX = (NewSize >> 4) + 1 ;        // Round up to next paragraph
  80.     else
  81.         _BX = NewSize >> 4 ;
  82.     _ES = Selector ;
  83.     _AH = 0x4A ;
  84.     Dos3Call() ;
  85.     return (_FLAGS & 0x0001) ? _AX : NO_ERROR;
  86. }
  87.